package dao

import (
	"context"
	"sale-admin/internal/dal"
	"sale-admin/internal/models"
	"strings"
	"time"

	"192.168.1.75/go-pkg/helper"
	"github.com/golang-module/carbon/v2"
	"gorm.io/gen/field"
	"gorm.io/gorm"
)

const (
	TOTAL_REPORT = iota
	ORDER_REPORT
	FACECOUNT_REPORT
	CLICK_REPORT
	TASK_REPORT
)

type RobotDailyReportInterface interface {
	WithMerchantID(merchantID string) RobotDailyReportInterface
	WithLocationID(locationID string) RobotDailyReportInterface
	WithRobotID(robotID string) RobotDailyReportInterface
	WithProvinceID(provinceID string) RobotDailyReportInterface
	WithCityID(cityID string) RobotDailyReportInterface
	WithDistrictID(districtID string) RobotDailyReportInterface
	WithTimePeriod(start int64, end int64) RobotDailyReportInterface
	WithPaginate(page, size int) RobotDailyReportInterface
	WithGroupType(int) RobotDailyReportInterface
	WithDataType(int) RobotDailyReportInterface
	WithOrderType(string) RobotDailyReportInterface
	WithSummary(int) RobotDailyReportInterface

	List() ([]*models.RobotDailyReport, int64, *models.RobotDailyReport, error)
	ActiveRobotList() ([]*models.RobotDailyReport, error)
	AbnormalDeviceList(abnormalType int) ([]string, error)
}

type RobotDailyReport struct {
	Ctx       context.Context
	Query     *dal.Query
	Tx        dal.IRobotDailyReportDo
	Summary   int
	DataType  int
	GroupType int
	Page      int
	Limit     int
}

func NewRobotDailyReport(ctx context.Context, db *gorm.DB) RobotDailyReportInterface {
	return &RobotDailyReport{
		Ctx:   ctx,
		Query: dal.Use(db),
		Tx:    dal.Use(db).RobotDailyReport.WithContext(ctx),
	}
}

// 查询字段
func (r RobotDailyReport) getSelectField(fieldType int) []field.Expr {
	m := r.Query.RobotDailyReport
	orderSelectField := []field.Expr{
		m.GMV.Sum().As(m.GMV.ColumnName().String()),
		m.PaymentAmount.Sum().As(m.PaymentAmount.ColumnName().String()),
		m.DiscountAmount.Sum().As(m.DiscountAmount.ColumnName().String()),
		m.TransactionAmount.Sum().As(m.TransactionAmount.ColumnName().String()),
		m.RefundAmount.Sum().As(m.RefundAmount.ColumnName().String()),
		m.TotalOrder.Sum().As(m.TotalOrder.ColumnName().String()),
		m.TotalPaidOrder.Sum().As(m.TotalPaidOrder.ColumnName().String()),
		m.TotalNotPaidOrder.Sum().As(m.TotalNotPaidOrder.ColumnName().String()),
		m.TotalRefundOrder.Sum().As(m.TotalRefundOrder.ColumnName().String()),
	}
	faceCountSelectField := []field.Expr{
		m.Facecount.Sum().As(m.Facecount.ColumnName().String()),
		m.FacecountFront.Sum().As(m.FacecountFront.ColumnName().String()),
		m.FacecountLeft.Sum().As(m.FacecountLeft.ColumnName().String()),
		m.FacecountRight.Sum().As(m.FacecountRight.ColumnName().String()),
		m.FacecountBack.Sum().As(m.FacecountBack.ColumnName().String()),
		m.Starecount.Sum().As(m.Starecount.ColumnName().String()),
		m.StarecountFront.Sum().As(m.StarecountFront.ColumnName().String()),
		m.StarecountLeft.Sum().As(m.StarecountLeft.ColumnName().String()),
		m.StarecountRight.Sum().As(m.StarecountRight.ColumnName().String()),
		m.StarecountBack.Sum().As(m.StarecountBack.ColumnName().String()),
	}
	clickSelectField := []field.Expr{
		m.TotalGoodsClick.Sum().As(m.TotalGoodsClick.ColumnName().String()),
		m.TotalScreenClick.Sum().As(m.TotalScreenClick.ColumnName().String()),
	}
	taskSelectField := []field.Expr{
		m.TotalOperationDuration.Sum().As(m.TotalOperationDuration.ColumnName().String()),
		m.TotalChargingDuration.Sum().As(m.TotalChargingDuration.ColumnName().String()),
		m.TotalIdleDuration.Sum().As(m.TotalIdleDuration.ColumnName().String()),
		m.TotalTaskDuration.Sum().As(m.TotalTaskDuration.ColumnName().String()),
		m.TotalTaskOdometer.Sum().As(m.TotalTaskOdometer.ColumnName().String()),
		m.TotalTaskRunCount.Sum().As(m.TotalTaskRunCount.ColumnName().String()),
		m.TotalToTaskDuration.Sum().As(m.TotalToTaskDuration.ColumnName().String()),
		m.TotalToChargingDuration.Sum().As(m.TotalToChargingDuration.ColumnName().String()),
		m.TotalFaultDuration.Sum().As(m.TotalFaultDuration.ColumnName().String()),
	}
	switch fieldType {
	case TOTAL_REPORT:
		selectField := append(orderSelectField, faceCountSelectField...)
		selectField = append(selectField, clickSelectField...)
		selectField = append(selectField, taskSelectField...)
		selectField = append(selectField, m.RobotName.Count().As("robot_count"))
		return selectField
	case ORDER_REPORT:
		return orderSelectField
	case FACECOUNT_REPORT:
		return faceCountSelectField
	case CLICK_REPORT:
		return clickSelectField
	case TASK_REPORT:
		return taskSelectField
	}
	return []field.Expr{}
}

// 条件 商户
func (r RobotDailyReport) WithMerchantID(merchantID string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if merchantID != "" {
		r.Tx = r.Tx.Where(m.MerchantID.In(strings.Split(merchantID, ",")...))
	} else {
		r.Tx = r.Tx.Where(field.NewInt(m.TableName(), m.MerchantID.ColumnName().String()).Gt(1))
	}
	return r
}

// 条件 商场
func (r RobotDailyReport) WithLocationID(locationID string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if locationID != "" {
		r.Tx = r.Tx.Where(m.LocationID.In(strings.Split(locationID, ",")...))
	}
	return r
}

// 条件 机器
func (r RobotDailyReport) WithRobotID(robotID string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if robotID != "" {
		r.Tx = r.Tx.Where(m.RobotName.In(strings.Split(robotID, ",")...))
	}
	return r
}

// 条件 省份id
func (r RobotDailyReport) WithProvinceID(provinceID string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if provinceID != "" {
		r.Tx = r.Tx.Where(m.ProvinceID.In(strings.Split(provinceID, ",")...))
	}
	return r
}

// 条件 城市id
func (r RobotDailyReport) WithCityID(cityID string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if cityID != "" {
		r.Tx = r.Tx.Where(m.CityID.In(strings.Split(cityID, ",")...))
	}
	return r
}

// 条件 区县id
func (r RobotDailyReport) WithDistrictID(districtID string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if districtID != "" {
		r.Tx = r.Tx.Where(m.DistrictID.In(strings.Split(districtID, ",")...))
	}
	return r
}

// 条件 起止时间
func (r RobotDailyReport) WithTimePeriod(startTime, endTime int64) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if startTime != 0 && endTime != 0 {
		r.Tx = r.Tx.Where(m.CreatedDate.Between(
			time.Unix(startTime, 0),
			time.Unix(endTime, 0),
		))
	} else {
		today := carbon.Parse(carbon.Now().ToDateString()).ToStdTime()
		r.Tx = r.Tx.Where(m.CreatedDate.Eq(today))
	}
	return r
}

// 分页
func (r RobotDailyReport) WithPaginate(page, limit int) RobotDailyReportInterface {
	r.Page = page
	r.Limit = limit
	return r
}

// 分组类型
func (r RobotDailyReport) WithGroupType(Type int) RobotDailyReportInterface {
	r.GroupType = Type
	return r
}

func (r RobotDailyReport) HandleGroup() []field.Expr {
	m := r.Query.RobotDailyReport

	selectField := []field.Expr{
		m.MerchantID,
		m.CreatedDate,
	}
	if r.GroupType == 0 { // 按天+机器分组
		selectField = append(selectField, m.RobotName, m.LocationID, m.ProvinceID, m.CityID, m.DistrictID)
		r.Tx.Group(m.CreatedDate, m.RobotName).
			Order(m.CreatedDate.Desc(), m.RobotName)
	} else if r.GroupType == 1 { // 机器分组
		selectField = append(selectField, m.RobotName, m.LocationID, m.ProvinceID, m.CityID, m.DistrictID)
		r.Tx.Group(m.RobotName).
			Order(m.RobotName)
	} else if r.GroupType == 2 { // 商户分组
		r.Tx.Group(m.MerchantID).
			Order(m.MerchantID)
	} else if r.GroupType == 3 { // 商场分组
		selectField = append(selectField, m.LocationID, m.ProvinceID, m.CityID, m.DistrictID)
		r.Tx.Group(m.LocationID).
			Order(m.LocationID)
	} else if r.GroupType == 4 { // 日期分组
		r.Tx.Group(m.CreatedDate).
			Order(m.CreatedDate.Desc())
	} else if r.GroupType == 5 { // 位置分组
		selectField = append(selectField, m.ProvinceID, m.CityID, m.DistrictID)
		r.Tx.Group(m.CityID).
			Order(m.CityID)
	} else if r.GroupType == 6 { // 区县分组
		selectField = append(selectField, m.ProvinceID, m.CityID, m.DistrictID)
		r.Tx.Group(m.DistrictID).
			Order(m.DistrictID)
	}
	return selectField
}

// 排序类型
// 1_1 -- 实付金额降序
// 1_2 -- 实付金额升序
// 2_1 -- 退款金额降序
// 2_2 -- 退款金额升序
// 3_1 -- 时间降序
// 3_2 -- 时间升序
func (r RobotDailyReport) WithOrderType(orderType string) RobotDailyReportInterface {
	m := r.Query.RobotDailyReport
	if orderType == "1_1" {
		r.Tx = r.Tx.Order(m.PaymentAmount.Sum().Desc())
	} else if orderType == "1_2" {
		r.Tx = r.Tx.Order(m.PaymentAmount.Sum())
	} else if orderType == "2_1" {
		r.Tx = r.Tx.Order(m.RefundAmount.Sum().Desc())
	} else if orderType == "2_2" {
		r.Tx = r.Tx.Order(m.RefundAmount.Sum())
	} else if orderType == "3_1" {
		r.Tx = r.Tx.Order(m.CreatedDate.Desc())
	} else if orderType == "3_2" {
		r.Tx = r.Tx.Order(m.CreatedDate)
	}
	return r
}

// 数据类型
func (r RobotDailyReport) WithDataType(dataType int) RobotDailyReportInterface {
	r.DataType = dataType
	return r
}

// 汇总类型
func (r RobotDailyReport) WithSummary(summary int) RobotDailyReportInterface {
	r.Summary = summary
	return r
}

// 计算汇总数据,动态返回字段
func (r RobotDailyReport) ReportSummary() (summary *models.RobotDailyReport) {
	selectField := r.getSelectField(r.DataType)
	tx := r.Tx.WithContext(r.Ctx)
	summary, _ = tx.Limit(-1).
		Offset(-1).
		Select(selectField...).
		Take()
	return summary
}

// 获取列表
func (r RobotDailyReport) List() (result []*models.RobotDailyReport, total int64, summary *models.RobotDailyReport, err error) {
	if r.Summary != 0 { // 为0时不汇总
		summary = r.ReportSummary()
	}
	// 拼接Group,确定查询字段
	normalField := r.HandleGroup()
	// 获取指定数据类型
	selectField := r.getSelectField(r.DataType)
	// 拼接常规字段
	selectField = append(selectField, normalField...)

	tx := r.Tx.WithContext(r.Ctx)
	offset, limit := Offset(r.Page, r.Limit)
	result, total, err = tx.Select(selectField...).
		FindByPage(offset, limit)
	return
}

// 活跃设备排名
func (r RobotDailyReport) ActiveRobotList() (result []*models.RobotDailyReport, err error) {
	m := r.Query.RobotDailyReport
	return r.Tx.Select(m.CreatedDate, m.RobotName, m.TotalTaskDuration).
		Order(m.TotalTaskDuration).
		Find()
}

// 异常设备列表
func (r RobotDailyReport) AbnormalDeviceList(abnormalType int) (list []string, err error) {
	m := r.Query.RobotDailyReport
	if abnormalType == 1 { // 0曝光
		r.Tx = r.Tx.Where(m.Facecount.Eq(0))
	} else if abnormalType == 2 { // 0点击
		r.Tx = r.Tx.Where(m.TotalGoodsClick.Eq(0))
	} else if abnormalType == 3 { // 0创单
		r.Tx = r.Tx.Where(m.TotalOrder.Eq(0))
	}
	r.Tx.Group(m.RobotName).Pluck(m.RobotName, &list)
	return
}

// 机器运营日报新增编辑
func (RobotDailyReport) Save(
	ctx context.Context, db *gorm.DB,
	MerchantID, RobotName, Date, ProvinceID, CityID, DistrictID, LocationID string,
	options ...RobotDailyReportOption,
) (err error) {
	m := dal.Use(db).RobotDailyReport

	var update RobotDailyReportSave
	update.MerchantID = &MerchantID
	update.ProvinceID = &ProvinceID
	update.CityID = &CityID
	update.DistrictID = &DistrictID
	update.LocationID = &LocationID
	update.UpdateFields = append(update.UpdateFields, m.MerchantID, m.ProvinceID, m.CityID, m.DistrictID, m.LocationID)

	for _, option := range options {
		option(&update)
	}

	dailyRobotNameCount, _ := m.WithContext(ctx).Where(
		m.RobotName.Eq(RobotName),
		m.CreatedDate.Eq(carbon.ParseByLayout(Date, carbon.DateLayout).ToStdTime()),
	).Count()
	if dailyRobotNameCount > 0 { // 编辑
		m.WithContext(ctx).Where(
			m.RobotName.Eq(RobotName),
			m.CreatedDate.Eq(carbon.ParseByLayout(Date, carbon.DateLayout).ToStdTime()),
		).Select(update.UpdateFields...).
			Updates(&update)
	} else { // 新增
		update.ID, _ = helper.UUID{}.String()
		createdDate := carbon.ParseByLayout(Date, carbon.DateLayout).ToStdTime()
		update.CreatedDate = &createdDate
		update.RobotName = &RobotName
		m.WithContext(ctx).Create(&update.RobotDailyReport)
	}

	return
}

type RobotDailyReportSave struct {
	models.RobotDailyReport
	UpdateFields []field.Expr `gorm:"-"`
}
type RobotDailyReportOption func(*RobotDailyReportSave)

// 截止昨天机器当前库存
func (r RobotDailyReport) WithGoodsInventory(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.GoodsInventory)
		s.GoodsInventory = &value
	}
}

// 截止昨天机器的允许最大库存
func (r RobotDailyReport) WithGoodsMaxInventory(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.GoodsMaxInventory)
		s.GoodsMaxInventory = &value
	}
}

// GMV
func (r RobotDailyReport) WithGMV(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.GMV)
		s.GMV = &value
	}
}

// 实付金额
func (r RobotDailyReport) WithPaymentAmount(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.PaymentAmount)
		s.PaymentAmount = &value
	}
}

// 交易金额
func (r RobotDailyReport) WithTransactionAmount(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TransactionAmount)
		s.TransactionAmount = &value
	}
}

// 优惠金额
func (r RobotDailyReport) WithDiscountAmount(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.DiscountAmount)
		s.DiscountAmount = &value
	}
}

// 退款金额
func (r RobotDailyReport) WithRefundAmount(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.RefundAmount)
		s.RefundAmount = &value
	}
}

// 抽奖赠送
func (r RobotDailyReport) WithGiveAmount(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.GiveAmount)
		s.GiveAmount = &value
	}
}

// 创单笔数
func (r RobotDailyReport) WithTotalOrder(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalOrder)
		s.TotalOrder = &value
	}
}

// 支付笔数
func (r RobotDailyReport) WithTotalPaidOrder(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalPaidOrder)
		s.TotalPaidOrder = &value
	}
}

// 未支付笔数
func (r RobotDailyReport) WithTotalNotPaidOrder(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalNotPaidOrder)
		s.TotalNotPaidOrder = &value
	}
}

// 退款笔数
func (r RobotDailyReport) WithTotalRefundOrder(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalRefundOrder)
		s.TotalRefundOrder = &value
	}
}

// 支付人数
func (r RobotDailyReport) WithTotalPaidUser(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalPaidUser)
		s.TotalPaidUser = &value
	}
}

// 屏幕点击量
func (r RobotDailyReport) WithTotalScreenClick(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalScreenClick)
		s.TotalScreenClick = &value
	}
}

// 商品点击量
func (r RobotDailyReport) WithTotalGoodsClick(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalGoodsClick)
		s.TotalGoodsClick = &value
	}
}

// 曝光量
func (r RobotDailyReport) WithFacecount(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.Facecount)
		s.Facecount = &value
	}
}

// 曝光量前
func (r RobotDailyReport) WithFacecountFront(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.FacecountFront)
		s.FacecountFront = &value
	}
}

// 曝光量左
func (r RobotDailyReport) WithFacecountLeft(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.FacecountLeft)
		s.FacecountLeft = &value
	}
}

// 曝光量右
func (r RobotDailyReport) WithFacecountRight(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.FacecountRight)
		s.FacecountRight = &value
	}
}

// 曝光量右
func (r RobotDailyReport) WithFacecountBack(value float64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.FacecountBack)
		s.FacecountBack = &value
	}
}

// 凝视
func (r RobotDailyReport) WithStarecount(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.Starecount)
		s.Starecount = &value
	}
}

// 前凝视
func (r RobotDailyReport) WithStarecountFront(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.StarecountFront)
		s.StarecountFront = &value
	}
}

// 左凝视
func (r RobotDailyReport) WithStarecountLeft(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.StarecountLeft)
		s.StarecountLeft = &value
	}
}

// 右凝视
func (r RobotDailyReport) WithStarecountRight(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.StarecountRight)
		s.StarecountRight = &value
	}
}

// 后凝视
func (r RobotDailyReport) WithStarecountBack(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.StarecountBack)
		s.StarecountBack = &value
	}
}

// 运营时长，单位毫秒
func (r RobotDailyReport) WithTotalOperationDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalOperationDuration)
		s.TotalOperationDuration = &value
	}
}

// 充电时长，单位秒
func (r RobotDailyReport) WithTotalChargingDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalChargingDuration)
		s.TotalChargingDuration = &value
	}
}

// 闲置时长, 单位秒
func (r RobotDailyReport) WithTotalIdleDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalIdleDuration)
		s.TotalIdleDuration = &value
	}
}

// 任务时长，单位毫秒
func (r RobotDailyReport) WithTotalTaskDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalTaskDuration)
		s.TotalTaskDuration = &value
	}
}

// 出门时长，单位毫秒
func (r RobotDailyReport) WithTotalToTaskDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalToTaskDuration)
		s.TotalToTaskDuration = &value
	}
}

// 回充时长，单位毫秒
func (r RobotDailyReport) WithTotalToChargingDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalToChargingDuration)
		s.TotalToChargingDuration = &value
	}
}

// 异常时长, 单位秒
func (r RobotDailyReport) WithTotalFaultDuration(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalFaultDuration)
		s.TotalFaultDuration = &value
	}
}

// 任务里程, 单位厘米
func (r RobotDailyReport) WithTotalTaskOdometer(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalTaskOdometer)
		s.TotalTaskOdometer = &value
	}
}

// 任务次数
func (r RobotDailyReport) WithTotalTaskRunCount(value int64) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.TotalTaskRunCount)
		s.TotalTaskRunCount = &value
	}
}

// 新城新店标识
func (r RobotDailyReport) WithOpeningFlag(value string) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.OpeningFlag)
		s.OpeningFlag = &value
	}
}

// 新城新店开业时间
func (r RobotDailyReport) WithOpeningTime(value string) RobotDailyReportOption {
	return func(s *RobotDailyReportSave) {
		s.UpdateFields = append(s.UpdateFields, dal.RobotDailyReport.OpeningTime)
		s.OpeningTime = &value
	}
}
